//
//  NSArray+JsonKit.m
//  pickpic
//
//  Created by GaoYongyue on 16/10/2.
//  Copyright © 2016年 MicroDream. All rights reserved.
//

#import "NSArray+JsonKit.h"

@implementation NSArray(JsonKit)
- (NSString *)cd_JSONString
{
    NSData *jsonData = [self cd_JSONData];
    if (!jsonData)
    {
        return @"";
    }

    return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
}

- (NSData *)cd_JSONData
{
    if (![NSJSONSerialization isValidJSONObject:self])
    {
        return nil;
    }

    NSError *error = nil;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:self options:kNilOptions error:&error];
    if (error != nil)
    {
        return nil;
    }

    return jsonData;
}

@end
